package jUnit_tests;

import static org.junit.Assert.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import model.Auction;
import model.AuctionCalendar;
import model.NonProfit;
import model.TimeObject;

import org.junit.Before;
import org.junit.Test;

import controller.ACSystem;

@SuppressWarnings("unused")
public class Junit_test_for_AuctionCalendar {
	
	private ACSystem acs;
	private AuctionCalendar ac;
	private Calendar cal;
	private Auction auc1;
	private Auction auc2;
	private Auction auc3;
	private Date d1;
	private Date d2;
	private Date d3;
	private TimeObject to1;
	private TimeObject to2;
	private TimeObject to3;
	private TimeObject to4;
	private TimeObject to5;
	private TimeObject to6;
	private NonProfit np1;
	private NonProfit np2;
	private NonProfit np3;
	private SimpleDateFormat my_format = new SimpleDateFormat("EE dd/MM/yyyy");
	
	@SuppressWarnings("deprecation")
	@Before
	public void setUp() {
		acs = new ACSystem();
		cal = Calendar.getInstance();
		ac = acs.getAuctionCalendar();
		cal.set(Calendar.DAY_OF_MONTH, 3);
		cal.set(Calendar.MONTH, 4); //MONTHS run 0-11
		cal.set(Calendar.YEAR, 2014);
		d1 = cal.getTime();
		//System.out.println(my_format.format(d1));
		d2 = new Date();
		d2.setDate(5);
		d2.setMonth(6);
		d2.setYear(114);
		//System.out.println(my_format.format(d2));
		d3 = new Date();
		d3.setDate(11);
		d3.setMonth(11);
		d3.setYear(2014);
		to1 = new TimeObject(11, 30,4);
		to2 = new TimeObject(13, 00,2);
		to3 = new TimeObject(14, 00,5);
		
		//all three auctions on same day
		auc1 = new Auction(d1, to1, to2, np1);
		auc2 = new Auction(d1, to3, to4, np2);
		auc3 = new Auction(d1, to5, to6, np3);
	}

	@Test
	public void testValid() {
		//Tests addAuction, isValidDate, isFull, add
		int e = ac.addAuction(auc1);
		assertEquals("Auction 1 failed to add", 0, e);
		
		//Simulate the passage of two days	
		ac.screwUpDate(48);
		Calendar cal2 = Calendar.getInstance();
		
		//Test setTodaysDate
		assertEquals("Calendar did not reset to current date", my_format.format(ac.getTodaysDate()), 
				my_format.format(cal2.getTime()));
		
		//Test list creation
		assertEquals("Size of list not right", 90, AuctionCalendar.getList().size());
	}

}
